package org.cangku.controller;

import org.cangku.dao.BrandDao;
import org.cangku.entity.Brand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/brand")
public class BrandController {

    @Autowired
    private BrandDao brandDao;

    @RequestMapping("/query")
    @ResponseBody
    public List<Brand> query(){
        return brandDao.query();
    }


    @RequestMapping("/querytj")
    @ResponseBody
    public Map<String,Object> query(int offset, int limit, int bid){
        Map<String,Object> map=new HashMap<String,Object>();
        map.put("rows",brandDao.queryTJ(offset,limit,bid));
        map.put("total",brandDao.getTJ());
        return map;
    }

    @RequestMapping("/add")
    @ResponseBody
    public Map<String,Object> add(Brand brand){
        boolean is = brandDao.addBrand(brand);
        Map<String,Object> map= new HashMap<String,Object>();
        map.put("rows",brandDao.query());
        map.put("total",brandDao.getTJ());
        return map;
    }

    @RequestMapping("/selectById")
    @ResponseBody
    public List<Brand> selectById(int bid){
        return brandDao.selectById(bid);
    }

    @RequestMapping("/edit")
    @ResponseBody
    public Map<String,Object> edit(Brand brand){
        boolean is = brandDao.editBrand(brand);
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("rows",brandDao.query());
        map.put("total",brandDao.getTJ());
        return map;
    }

    @RequestMapping("/delete")
    @ResponseBody
    public Map<String,Object> delete(int bid){
        boolean is = brandDao.deletebyid(bid);
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("rows",brandDao.query());
        map.put("total",brandDao.getTJ());
        return map;
    }
}
